﻿using System;
using System.Runtime.InteropServices;
using System.Text;

namespace IOP.OpenType
{
    /// <summary>
    /// Array of four uint8s (length = 32 bits) used to identify a table, design-variation axis, script, language system, feature, or baseline
    /// </summary>
    public readonly struct Tag
    {
        private readonly uint origin;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="number"></param>
        public Tag(uint number) => origin = number;

        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="tag"></param>
        public static implicit operator string(Tag tag)
        {
            Span<byte> b = stackalloc byte[4];
            Span<uint> u = stackalloc uint[] { tag.origin };
            b = MemoryMarshal.Cast<uint, byte>(u);
            return Encoding.ASCII.GetString(b);
        }
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="number"></param>
        public static implicit operator Tag(uint number) => new Tag(number);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="number"></param>
        public static implicit operator Tag(int number) => new Tag((uint)number);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string s = this;
            return s;
        }
    }
}
